#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <set>
using namespace std;
class Solution
{
public:
    int pivotIndex(vector<int> &nums)
    {
        if (nums.size() <= 0)
            return -1;
        vector<int> csum(nums.begin(), nums.end());
        for (int i = 1; i < csum.size(); ++i)
        {
            csum[i] += csum[i - 1];
        }
        int totalsum = csum[csum.size() - 1];
        for (int i = 0; i < csum.size(); ++i)
        {
            if (csum[i] - nums[i] == totalsum - csum[i])
                return i;
        }
        return -1;
    }
};